In [65]:
import geopandas as gpd
import pandas as pd
import mapclassify
import pysal
import matplotlib.pyplot as plt
from pysal.explore import esda
from pysal.explore import inequality
from pysal.lib import weights
from shapely.geometry import LineString, MultiLineString, Point
import numpy as np
from geosnap.analyze import isochrones_from_id, isochrones_from_gdf, pdna_to_adj
from geosnap.io import get_acs, get_lodes
from geosnap import DataStore
import os
from random import sample
import tobler
import pandana as pdna
import quilt3 as q3
from tobler.area_weighted import area_interpolate
In [66]:
datasets = DataStore('/srv/data/geosnap')
In [67]:
sd_tracts = get_acs(datasets, county_fips='06073', years=[2021])
/opt/tljh/user/lib/python3.10/site-packages/geosnap/_data.py:16: UserWarning: Streaming data from S3. Use `geosnap.io.store_acs()` to store the data locally for better performance warn(warning_msg) /opt/tljh/user/lib/python3.10/site-packages/geosnap/io/util.py:275: UserWarning: Unable to find local adjustment year for 2021. Attempting from online data warn( /opt/tljh/user/lib/python3.10/site-packages/geosnap/io/constructors.py:215: UserWarning: Currency columns unavailable at this resolution; not adjusting for inflation warn(
In [68]:
os.getcwd()
Out[68]:
'/home/jupyter-gbartel2616/notes/git/project/Employment-Centers-'
In [69]:
lodes = gpd.read_parquet("lodes.parquet")
In [70]:
lodes
Out[70]:
| geoid | year | CFA01 | CFA02 | CFA03 | CFA04 | CFA05 | CFS01 | CFS02 | CFS03 | ... | naics_55 | naics_56 | naics_61 | naics_62 | naics_71 | naics_72 | naics_81 | naics_92 | population | total_employees | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 214 | 060730004002000 | 2021 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | ... | 2.0 | 68.0 | 0.0 | 9820.0 | 0.0 | 0.0 | 18.0 | 0.0 | 121 | 9995.0 |
| 229 | 060730004004000 | 2021 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | ... | 0.0 | 3.0 | 4.0 | 4177.0 | 0.0 | 0.0 | 0.0 | 0.0 | 1019 | 4272.0 |
| 1604 | 060730028011010 | 2021 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | ... | 0.0 | 23.0 | 3343.0 | 0.0 | 0.0 | 35.0 | 568.0 | 0.0 | 27 | 4007.0 |
| 3062 | 060730038001018 | 2021 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | ... | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 984 | 4148.0 |
| 3859 | 060730053021009 | 2021 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | ... | 44.0 | 0.0 | 42.0 | 2.0 | 26.0 | 82.0 | 2.0 | 11185.0 | 48 | 12455.0 |
| 4265 | 060730062001000 | 2021 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | ... | 0.0 | 21.0 | 0.0 | 0.0 | 0.0 | 162.0 | 66.0 | 0.0 | 0 | 5000.0 |
| 5937 | 060730083051007 | 2021 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | ... | 0.0 | 25.0 | 20987.0 | 0.0 | 0.0 | 49.0 | 3.0 | 1.0 | 0 | 21112.0 |
| 5948 | 060730083051018 | 2021 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | ... | 0.0 | 80.0 | 0.0 | 4071.0 | 0.0 | 0.0 | 3.0 | 0.0 | 66 | 4263.0 |
| 6079 | 060730083121001 | 2021 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | ... | 0.0 | 28.0 | 46.0 | 3026.0 | 0.0 | 260.0 | 106.0 | 0.0 | 427 | 6133.0 |
| 6410 | 060730083391005 | 2021 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | ... | 0.0 | 0.0 | 664.0 | 2.0 | 1.0 | 15.0 | 2.0 | 0.0 | 0 | 4571.0 |
| 6423 | 060730083391018 | 2021 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | ... | 0.0 | 6.0 | 1.0 | 161.0 | 0.0 | 33.0 | 0.0 | 0.0 | 0 | 4575.0 |
| 6439 | 060730083391034 | 2021 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | ... | 2678.0 | 190.0 | 177.0 | 1019.0 | 0.0 | 3.0 | 14.0 | 1.0 | 1541 | 14041.0 |
| 6519 | 060730083462000 | 2021 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | ... | 15.0 | 0.0 | 37.0 | 19.0 | 0.0 | 55.0 | 43.0 | 0.0 | 9 | 8443.0 |
| 6543 | 060730083462024 | 2021 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | ... | 1494.0 | 63.0 | 0.0 | 81.0 | 0.0 | 9.0 | 14.0 | 0.0 | 12 | 5027.0 |
| 6676 | 060730083501024 | 2021 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | ... | 205.0 | 5802.0 | 10.0 | 74.0 | 1.0 | 75.0 | 120.0 | 2.0 | 8 | 7717.0 |
| 6705 | 060730083502006 | 2021 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | ... | 72.0 | 2192.0 | 258.0 | 534.0 | 3.0 | 70.0 | 43.0 | 3.0 | 0 | 8796.0 |
| 7096 | 060730083692001 | 2021 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | ... | 0.0 | 5101.0 | 0.0 | 83.0 | 3.0 | 66.0 | 23.0 | 1.0 | 0 | 6641.0 |
| 7218 | 060730083762000 | 2021 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | ... | 0.0 | 7.0 | 0.0 | 3.0 | 30.0 | 161.0 | 6.0 | 0.0 | 702 | 4893.0 |
| 7222 | 060730083763000 | 2021 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | ... | 0.0 | 0.0 | 0.0 | 20.0 | 8.0 | 8.0 | 1.0 | 0.0 | 2905 | 4241.0 |
| 7690 | 060730085111005 | 2021 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | ... | 2.0 | 152.0 | 2.0 | 15.0 | 448.0 | 53.0 | 55.0 | 21002.0 | 12 | 23927.0 |
| 7700 | 060730085111015 | 2021 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | ... | 334.0 | 112.0 | 1.0 | 2523.0 | 0.0 | 33.0 | 200.0 | 0.0 | 12 | 4067.0 |
| 7768 | 060730085113001 | 2021 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | ... | 212.0 | 971.0 | 60.0 | 885.0 | 278.0 | 11.0 | 51.0 | 0.0 | 14 | 4836.0 |
| 7771 | 060730085113004 | 2021 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | ... | 267.0 | 917.0 | 31.0 | 770.0 | 2.0 | 82.0 | 83.0 | 5.0 | 12 | 9172.0 |
| 7775 | 060730085113008 | 2021 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | ... | 4152.0 | 0.0 | 971.0 | 50.0 | 1.0 | 50.0 | 11.0 | 0.0 | 957 | 5283.0 |
| 7886 | 060730087021003 | 2021 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | ... | 0.0 | 1.0 | 0.0 | 6416.0 | 0.0 | 533.0 | 0.0 | 0.0 | 0 | 6952.0 |
| 8522 | 060730093074013 | 2021 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | ... | 47.0 | 1168.0 | 30.0 | 2156.0 | 7.0 | 1.0 | 90.0 | 10.0 | 12 | 4871.0 |
| 14242 | 060730150022003 | 2021 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | ... | 0.0 | 2.0 | 0.0 | 3664.0 | 0.0 | 390.0 | 0.0 | 0.0 | 0 | 4192.0 |
| 16871 | 060730170492019 | 2021 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | ... | 0.0 | 0.0 | 0.0 | 179.0 | 0.0 | 12.0 | 4.0 | 0.0 | 2 | 5250.0 |
| 17007 | 060730170561002 | 2021 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | ... | 636.0 | 11.0 | 3007.0 | 1164.0 | 0.0 | 75.0 | 16.0 | 0.0 | 200 | 6872.0 |
| 17563 | 060730170711003 | 2021 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | ... | 904.0 | 103.0 | 5.0 | 14.0 | 0.0 | 12.0 | 19.0 | 0.0 | 0 | 5134.0 |
| 28563 | 060730221012009 | 2021 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | ... | 245.0 | 539.0 | 45.0 | 268.0 | 4.0 | 28.0 | 9.0 | 0.0 | 30 | 5978.0 |
31 rows × 59 columns
In [71]:
lodes.head()
Out[71]:
| geoid | year | CFA01 | CFA02 | CFA03 | CFA04 | CFA05 | CFS01 | CFS02 | CFS03 | ... | naics_55 | naics_56 | naics_61 | naics_62 | naics_71 | naics_72 | naics_81 | naics_92 | population | total_employees | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 214 | 060730004002000 | 2021 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | ... | 2.0 | 68.0 | 0.0 | 9820.0 | 0.0 | 0.0 | 18.0 | 0.0 | 121 | 9995.0 |
| 229 | 060730004004000 | 2021 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | ... | 0.0 | 3.0 | 4.0 | 4177.0 | 0.0 | 0.0 | 0.0 | 0.0 | 1019 | 4272.0 |
| 1604 | 060730028011010 | 2021 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | ... | 0.0 | 23.0 | 3343.0 | 0.0 | 0.0 | 35.0 | 568.0 | 0.0 | 27 | 4007.0 |
| 3062 | 060730038001018 | 2021 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | ... | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 984 | 4148.0 |
| 3859 | 060730053021009 | 2021 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | ... | 44.0 | 0.0 | 42.0 | 2.0 | 26.0 | 82.0 | 2.0 | 11185.0 | 48 | 12455.0 |
5 rows × 59 columns
In [72]:
sd_tracts.columns
Out[72]:
Index(['geoid', 'n_total_housing_units', 'n_vacant_housing_units',
'n_occupied_housing_units', 'n_owner_occupied_housing_units',
'n_renter_occupied_housing_units',
'n_housing_units_multiunit_structures_denom',
'n_housing_units_multiunit_structures', 'n_total_housing_units_sample',
'median_home_value', 'median_contract_rent',
'n_occupied_housing_units_sample', 'n_persons_under_18',
'n_persons_over_60', 'n_persons_over_75', 'n_persons_over_15',
'n_persons_over_25', 'n_married', 'n_widowed_divorced',
'n_total_families', 'n_female_headed_families',
'n_nonhisp_white_persons', 'n_nonhisp_black_persons',
'n_hispanic_persons', 'n_native_persons', 'n_hawaiian_persons',
'n_asian_indian_persons', 'n_asian_persons', 'n_civilians_over_16',
'n_veterans', 'median_household_income', 'n_total_households',
'per_capita_income', 'n_poverty_families_children',
'n_edu_college_greater', 'n_edu_hs_less', 'n_total_pop',
'p_vacant_housing_units', 'p_owner_occupied_units',
'p_housing_units_multiunit_structures', 'p_persons_under_18',
'p_persons_over_60', 'p_persons_over_75', 'p_married',
'p_widowed_divorced', 'p_female_headed_families',
'p_nonhisp_white_persons', 'p_nonhisp_black_persons',
'p_hispanic_persons', 'p_native_persons', 'p_asian_persons',
'p_hawaiian_persons', 'p_asian_indian_persons', 'p_edu_hs_less',
'p_edu_college_greater', 'p_veterans', 'geometry', 'year'],
dtype='object')
In [73]:
# get age and education from lodes and compare to the education level for people in the acs (people living in the area)
In [74]:
demographics= sd_tracts[['p_hispanic_persons','p_native_persons','p_asian_persons','p_hawaiian_persons','p_asian_indian_persons','p_edu_hs_less','p_edu_college_greater','geoid','geometry']]
In [75]:
demographics
Out[75]:
| p_hispanic_persons | p_native_persons | p_asian_persons | p_hawaiian_persons | p_asian_indian_persons | p_edu_hs_less | p_edu_college_greater | geoid | geometry | |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 21.483555 | 0.0 | 2.029391 | 0.839748 | 2.029391 | 3.050524 | 82.745472 | 060730001001 | MULTIPOLYGON (((-117.18984 32.75861, -117.1896... |
| 1 | 7.858546 | 0.0 | 5.762934 | 0.000000 | 5.762934 | 2.645051 | 77.303754 | 060730001002 | MULTIPOLYGON (((-117.19490 32.75278, -117.1947... |
| 2 | 1.070039 | 0.0 | 8.657588 | 0.000000 | 8.657588 | 2.948718 | 81.282051 | 060730002011 | MULTIPOLYGON (((-117.17887 32.75765, -117.1779... |
| 3 | 8.743169 | 0.0 | 3.122560 | 0.000000 | 3.122560 | 0.000000 | 71.321462 | 060730002012 | MULTIPOLYGON (((-117.17415 32.75561, -117.1739... |
| 4 | 14.860140 | 0.0 | 0.000000 | 0.000000 | 0.000000 | 9.262760 | 51.417769 | 060730002021 | MULTIPOLYGON (((-117.18241 32.74255, -117.1819... |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 2053 | 16.328709 | 0.0 | 11.526147 | 0.000000 | 11.526147 | 2.820685 | 67.427804 | 060730221021 | MULTIPOLYGON (((-117.29552 33.10990, -117.2947... |
| 2054 | 5.982275 | 0.0 | 11.595273 | 0.000000 | 11.595273 | 2.485660 | 85.659656 | 060730221022 | MULTIPOLYGON (((-117.28155 33.11199, -117.2815... |
| 2055 | 17.501088 | 0.0 | 5.267741 | 0.000000 | 5.267741 | 7.040998 | 67.201426 | 060730221023 | MULTIPOLYGON (((-117.30199 33.12209, -117.3019... |
| 2056 | 75.200642 | 0.0 | 5.939005 | 0.000000 | 5.939005 | 51.790831 | 19.412607 | 060730221024 | MULTIPOLYGON (((-117.29064 33.11983, -117.2906... |
| 2057 | NaN | NaN | NaN | NaN | NaN | NaN | NaN | 060739901000 | MULTIPOLYGON (((-117.61104 33.33412, -117.6086... |
2058 rows × 9 columns
In [76]:
lodes.columns
Out[76]:
Index(['geoid', 'year', 'CFA01', 'CFA02', 'CFA03', 'CFA04', 'CFA05', 'CFS01',
'CFS02', 'CFS03', 'CFS04', 'CFS05', 'aland20', 'awater20',
'create_date', 'earnings_1251_3333', 'earnings_over_3333',
'earnings_under_1250', 'education_bachelors', 'education_hs',
'education_lths', 'education_some_college', 'employees_30_54',
'employees_55plus', 'employees_asian', 'employees_black',
'employees_female', 'employees_hawaiian_pi', 'employees_hispanic',
'employees_male', 'employees_native_american', 'employees_not_hispanic',
'employees_twoplus_races', 'employees_under_30', 'employees_white',
'geometry', 'housing_units', 'naics_11', 'naics_21', 'naics_22',
'naics_23', 'naics_31_33', 'naics_42', 'naics_44_45', 'naics_48_49',
'naics_51', 'naics_52', 'naics_53', 'naics_54', 'naics_55', 'naics_56',
'naics_61', 'naics_62', 'naics_71', 'naics_72', 'naics_81', 'naics_92',
'population', 'total_employees'],
dtype='object')
In [77]:
lodes_demos= lodes[['education_bachelors','education_hs','education_lths','education_some_college','employees_30_54','employees_55plus','employees_under_30','geoid']]
In [78]:
lodes_demos
Out[78]:
| education_bachelors | education_hs | education_lths | education_some_college | employees_30_54 | employees_55plus | employees_under_30 | geoid | |
|---|---|---|---|---|---|---|---|---|
| 214 | 3266.0 | 1347.0 | 990.0 | 2136.0 | 6017.0 | 1722.0 | 2256.0 | 060730004002000 |
| 229 | 1174.0 | 717.0 | 542.0 | 1187.0 | 2650.0 | 970.0 | 652.0 | 060730004004000 |
| 1604 | 1620.0 | 563.0 | 321.0 | 871.0 | 2272.0 | 1103.0 | 632.0 | 060730028011010 |
| 3062 | 542.0 | 840.0 | 891.0 | 1031.0 | 2316.0 | 988.0 | 844.0 | 060730038001018 |
| 3859 | 3459.0 | 2196.0 | 1479.0 | 3853.0 | 8092.0 | 2895.0 | 1468.0 | 060730053021009 |
| 4265 | 1152.0 | 975.0 | 638.0 | 1295.0 | 2719.0 | 1341.0 | 940.0 | 060730062001000 |
| 5937 | 7181.0 | 2678.0 | 1747.0 | 4321.0 | 12173.0 | 3754.0 | 5185.0 | 060730083051007 |
| 5948 | 2425.0 | 270.0 | 92.0 | 1152.0 | 2794.0 | 1145.0 | 324.0 | 060730083051018 |
| 6079 | 2347.0 | 812.0 | 646.0 | 1426.0 | 3788.0 | 1443.0 | 902.0 | 060730083121001 |
| 6410 | 1957.0 | 662.0 | 371.0 | 1095.0 | 3106.0 | 979.0 | 486.0 | 060730083391005 |
| 6423 | 2014.0 | 627.0 | 361.0 | 1048.0 | 2897.0 | 1153.0 | 525.0 | 060730083391018 |
| 6439 | 5547.0 | 1883.0 | 1231.0 | 3226.0 | 9104.0 | 2783.0 | 2154.0 | 060730083391034 |
| 6519 | 3247.0 | 1067.0 | 771.0 | 1768.0 | 5377.0 | 1476.0 | 1590.0 | 060730083462000 |
| 6543 | 2456.0 | 528.0 | 399.0 | 926.0 | 3537.0 | 772.0 | 718.0 | 060730083462024 |
| 6676 | 1758.0 | 1146.0 | 780.0 | 1690.0 | 4410.0 | 964.0 | 2343.0 | 060730083501024 |
| 6705 | 2230.0 | 1377.0 | 1059.0 | 1960.0 | 5030.0 | 1596.0 | 2170.0 | 060730083502006 |
| 7096 | 1886.0 | 1026.0 | 676.0 | 1670.0 | 4159.0 | 1099.0 | 1383.0 | 060730083692001 |
| 7218 | 527.0 | 530.0 | 446.0 | 714.0 | 1685.0 | 532.0 | 2676.0 | 060730083762000 |
| 7222 | 1798.0 | 579.0 | 343.0 | 907.0 | 3095.0 | 532.0 | 614.0 | 060730083763000 |
| 7690 | 7071.0 | 4113.0 | 2610.0 | 7266.0 | 15950.0 | 5110.0 | 2867.0 | 060730085111005 |
| 7700 | 1179.0 | 688.0 | 548.0 | 1100.0 | 2540.0 | 975.0 | 552.0 | 060730085111015 |
| 7768 | 1177.0 | 852.0 | 732.0 | 1128.0 | 2854.0 | 1035.0 | 947.0 | 060730085113001 |
| 7771 | 2558.0 | 1638.0 | 1179.0 | 2447.0 | 5386.0 | 2436.0 | 1350.0 | 060730085113004 |
| 7775 | 1633.0 | 890.0 | 644.0 | 1493.0 | 3389.0 | 1271.0 | 623.0 | 060730085113008 |
| 7886 | 2190.0 | 1128.0 | 714.0 | 1992.0 | 4288.0 | 1736.0 | 928.0 | 060730087021003 |
| 8522 | 1094.0 | 781.0 | 648.0 | 1198.0 | 2477.0 | 1244.0 | 1150.0 | 060730093074013 |
| 14242 | 1195.0 | 689.0 | 485.0 | 1254.0 | 2653.0 | 970.0 | 569.0 | 060730150022003 |
| 16871 | 1337.0 | 852.0 | 600.0 | 1370.0 | 3317.0 | 842.0 | 1091.0 | 060730170492019 |
| 17007 | 2555.0 | 989.0 | 612.0 | 1714.0 | 4066.0 | 1804.0 | 1002.0 | 060730170561002 |
| 17563 | 1867.0 | 668.0 | 465.0 | 1214.0 | 2866.0 | 1348.0 | 920.0 | 060730170711003 |
| 28563 | 1756.0 | 994.0 | 752.0 | 1380.0 | 3553.0 | 1329.0 | 1096.0 | 060730221012009 |
In [79]:
lodes_ages=lodes[['geoid','employees_30_54','employees_55plus','employees_under_30']]
In [80]:
lodes_ages
Out[80]:
| geoid | employees_30_54 | employees_55plus | employees_under_30 | |
|---|---|---|---|---|
| 214 | 060730004002000 | 6017.0 | 1722.0 | 2256.0 |
| 229 | 060730004004000 | 2650.0 | 970.0 | 652.0 |
| 1604 | 060730028011010 | 2272.0 | 1103.0 | 632.0 |
| 3062 | 060730038001018 | 2316.0 | 988.0 | 844.0 |
| 3859 | 060730053021009 | 8092.0 | 2895.0 | 1468.0 |
| 4265 | 060730062001000 | 2719.0 | 1341.0 | 940.0 |
| 5937 | 060730083051007 | 12173.0 | 3754.0 | 5185.0 |
| 5948 | 060730083051018 | 2794.0 | 1145.0 | 324.0 |
| 6079 | 060730083121001 | 3788.0 | 1443.0 | 902.0 |
| 6410 | 060730083391005 | 3106.0 | 979.0 | 486.0 |
| 6423 | 060730083391018 | 2897.0 | 1153.0 | 525.0 |
| 6439 | 060730083391034 | 9104.0 | 2783.0 | 2154.0 |
| 6519 | 060730083462000 | 5377.0 | 1476.0 | 1590.0 |
| 6543 | 060730083462024 | 3537.0 | 772.0 | 718.0 |
| 6676 | 060730083501024 | 4410.0 | 964.0 | 2343.0 |
| 6705 | 060730083502006 | 5030.0 | 1596.0 | 2170.0 |
| 7096 | 060730083692001 | 4159.0 | 1099.0 | 1383.0 |
| 7218 | 060730083762000 | 1685.0 | 532.0 | 2676.0 |
| 7222 | 060730083763000 | 3095.0 | 532.0 | 614.0 |
| 7690 | 060730085111005 | 15950.0 | 5110.0 | 2867.0 |
| 7700 | 060730085111015 | 2540.0 | 975.0 | 552.0 |
| 7768 | 060730085113001 | 2854.0 | 1035.0 | 947.0 |
| 7771 | 060730085113004 | 5386.0 | 2436.0 | 1350.0 |
| 7775 | 060730085113008 | 3389.0 | 1271.0 | 623.0 |
| 7886 | 060730087021003 | 4288.0 | 1736.0 | 928.0 |
| 8522 | 060730093074013 | 2477.0 | 1244.0 | 1150.0 |
| 14242 | 060730150022003 | 2653.0 | 970.0 | 569.0 |
| 16871 | 060730170492019 | 3317.0 | 842.0 | 1091.0 |
| 17007 | 060730170561002 | 4066.0 | 1804.0 | 1002.0 |
| 17563 | 060730170711003 | 2866.0 | 1348.0 | 920.0 |
| 28563 | 060730221012009 | 3553.0 | 1329.0 | 1096.0 |
In [81]:
acs_variables = ['p_hispanic_persons','p_native_persons','p_asian_persons','p_hawaiian_persons','p_asian_indian_persons','n_nonhisp_white_persons', 'n_nonhisp_black_persons']
num_classes = 10
In [82]:
for var in acs_variables:
sd_tracts[f'{var}_deciles'] = pd.qcut(sd_tracts[var], num_classes, labels=False, duplicates='drop')
fig, ax = plt.subplots(1,1)
sd_tracts.plot(column=f'{var}_deciles', cmap='viridis', linewidth=0.25, ax=ax, edgecolor='0.8', legend=True)
ax.set_title(f'{var}')
plt.show()
In [83]:
lodes_variables = ['education_bachelors','education_hs','education_lths','education_some_college','employees_30_54','employees_55plus','employees_under_30','geoid']
num_classes = 10
In [84]:
demographics = demographics.dropna()
In [85]:
lgeoid = lodes_demos.geoid
dgeoid = demographics.geoid
In [86]:
lgeoid.head()
Out[86]:
214 060730004002000 229 060730004004000 1604 060730028011010 3062 060730038001018 3859 060730053021009 Name: geoid, dtype: object
In [87]:
dgeoid.head()
Out[87]:
0 060730001001 1 060730001002 2 060730002011 3 060730002012 4 060730002021 Name: geoid, dtype: object
In [88]:
len(dgeoid[0])
Out[88]:
12
In [89]:
len(lgeoid.values[0])
Out[89]:
15
In [90]:
short_geoid = [code[:12] for code in lgeoid.values]
In [91]:
short_geoid
Out[91]:
['060730004002', '060730004004', '060730028011', '060730038001', '060730053021', '060730062001', '060730083051', '060730083051', '060730083121', '060730083391', '060730083391', '060730083391', '060730083462', '060730083462', '060730083501', '060730083502', '060730083692', '060730083762', '060730083763', '060730085111', '060730085111', '060730085113', '060730085113', '060730085113', '060730087021', '060730093074', '060730150022', '060730170492', '060730170561', '060730170711', '060730221012']
In [92]:
lodes_demos['shortgeoid']=short_geoid
/tmp/ipykernel_1998999/2478044967.py:1: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy lodes_demos['shortgeoid']=short_geoid
In [93]:
lodes_demos
Out[93]:
| education_bachelors | education_hs | education_lths | education_some_college | employees_30_54 | employees_55plus | employees_under_30 | geoid | shortgeoid | |
|---|---|---|---|---|---|---|---|---|---|
| 214 | 3266.0 | 1347.0 | 990.0 | 2136.0 | 6017.0 | 1722.0 | 2256.0 | 060730004002000 | 060730004002 |
| 229 | 1174.0 | 717.0 | 542.0 | 1187.0 | 2650.0 | 970.0 | 652.0 | 060730004004000 | 060730004004 |
| 1604 | 1620.0 | 563.0 | 321.0 | 871.0 | 2272.0 | 1103.0 | 632.0 | 060730028011010 | 060730028011 |
| 3062 | 542.0 | 840.0 | 891.0 | 1031.0 | 2316.0 | 988.0 | 844.0 | 060730038001018 | 060730038001 |
| 3859 | 3459.0 | 2196.0 | 1479.0 | 3853.0 | 8092.0 | 2895.0 | 1468.0 | 060730053021009 | 060730053021 |
| 4265 | 1152.0 | 975.0 | 638.0 | 1295.0 | 2719.0 | 1341.0 | 940.0 | 060730062001000 | 060730062001 |
| 5937 | 7181.0 | 2678.0 | 1747.0 | 4321.0 | 12173.0 | 3754.0 | 5185.0 | 060730083051007 | 060730083051 |
| 5948 | 2425.0 | 270.0 | 92.0 | 1152.0 | 2794.0 | 1145.0 | 324.0 | 060730083051018 | 060730083051 |
| 6079 | 2347.0 | 812.0 | 646.0 | 1426.0 | 3788.0 | 1443.0 | 902.0 | 060730083121001 | 060730083121 |
| 6410 | 1957.0 | 662.0 | 371.0 | 1095.0 | 3106.0 | 979.0 | 486.0 | 060730083391005 | 060730083391 |
| 6423 | 2014.0 | 627.0 | 361.0 | 1048.0 | 2897.0 | 1153.0 | 525.0 | 060730083391018 | 060730083391 |
| 6439 | 5547.0 | 1883.0 | 1231.0 | 3226.0 | 9104.0 | 2783.0 | 2154.0 | 060730083391034 | 060730083391 |
| 6519 | 3247.0 | 1067.0 | 771.0 | 1768.0 | 5377.0 | 1476.0 | 1590.0 | 060730083462000 | 060730083462 |
| 6543 | 2456.0 | 528.0 | 399.0 | 926.0 | 3537.0 | 772.0 | 718.0 | 060730083462024 | 060730083462 |
| 6676 | 1758.0 | 1146.0 | 780.0 | 1690.0 | 4410.0 | 964.0 | 2343.0 | 060730083501024 | 060730083501 |
| 6705 | 2230.0 | 1377.0 | 1059.0 | 1960.0 | 5030.0 | 1596.0 | 2170.0 | 060730083502006 | 060730083502 |
| 7096 | 1886.0 | 1026.0 | 676.0 | 1670.0 | 4159.0 | 1099.0 | 1383.0 | 060730083692001 | 060730083692 |
| 7218 | 527.0 | 530.0 | 446.0 | 714.0 | 1685.0 | 532.0 | 2676.0 | 060730083762000 | 060730083762 |
| 7222 | 1798.0 | 579.0 | 343.0 | 907.0 | 3095.0 | 532.0 | 614.0 | 060730083763000 | 060730083763 |
| 7690 | 7071.0 | 4113.0 | 2610.0 | 7266.0 | 15950.0 | 5110.0 | 2867.0 | 060730085111005 | 060730085111 |
| 7700 | 1179.0 | 688.0 | 548.0 | 1100.0 | 2540.0 | 975.0 | 552.0 | 060730085111015 | 060730085111 |
| 7768 | 1177.0 | 852.0 | 732.0 | 1128.0 | 2854.0 | 1035.0 | 947.0 | 060730085113001 | 060730085113 |
| 7771 | 2558.0 | 1638.0 | 1179.0 | 2447.0 | 5386.0 | 2436.0 | 1350.0 | 060730085113004 | 060730085113 |
| 7775 | 1633.0 | 890.0 | 644.0 | 1493.0 | 3389.0 | 1271.0 | 623.0 | 060730085113008 | 060730085113 |
| 7886 | 2190.0 | 1128.0 | 714.0 | 1992.0 | 4288.0 | 1736.0 | 928.0 | 060730087021003 | 060730087021 |
| 8522 | 1094.0 | 781.0 | 648.0 | 1198.0 | 2477.0 | 1244.0 | 1150.0 | 060730093074013 | 060730093074 |
| 14242 | 1195.0 | 689.0 | 485.0 | 1254.0 | 2653.0 | 970.0 | 569.0 | 060730150022003 | 060730150022 |
| 16871 | 1337.0 | 852.0 | 600.0 | 1370.0 | 3317.0 | 842.0 | 1091.0 | 060730170492019 | 060730170492 |
| 17007 | 2555.0 | 989.0 | 612.0 | 1714.0 | 4066.0 | 1804.0 | 1002.0 | 060730170561002 | 060730170561 |
| 17563 | 1867.0 | 668.0 | 465.0 | 1214.0 | 2866.0 | 1348.0 | 920.0 | 060730170711003 | 060730170711 |
| 28563 | 1756.0 | 994.0 | 752.0 | 1380.0 | 3553.0 | 1329.0 | 1096.0 | 060730221012009 | 060730221012 |
In [94]:
lodes_acs=lodes_demos.merge(demographics, left_on='shortgeoid', right_on='geoid')
In [95]:
lodes_acs
Out[95]:
| education_bachelors | education_hs | education_lths | education_some_college | employees_30_54 | employees_55plus | employees_under_30 | geoid_x | shortgeoid | p_hispanic_persons | p_native_persons | p_asian_persons | p_hawaiian_persons | p_asian_indian_persons | p_edu_hs_less | p_edu_college_greater | geoid_y | geometry | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 3266.0 | 1347.0 | 990.0 | 2136.0 | 6017.0 | 1722.0 | 2256.0 | 060730004002000 | 060730004002 | 13.447172 | 0.000000 | 16.969050 | 0.000000 | 16.969050 | 0.000000 | 61.388286 | 060730004002 | MULTIPOLYGON (((-117.17087 32.75865, -117.1701... |
| 1 | 1174.0 | 717.0 | 542.0 | 1187.0 | 2650.0 | 970.0 | 652.0 | 060730004004000 | 060730004004 | 20.452311 | 0.000000 | 11.799410 | 0.000000 | 11.799410 | 1.039261 | 64.896074 | 060730004004 | MULTIPOLYGON (((-117.16746 32.75917, -117.1668... |
| 2 | 1620.0 | 563.0 | 321.0 | 871.0 | 2272.0 | 1103.0 | 632.0 | 060730028011010 | 060730028011 | 17.220544 | 0.000000 | 8.836858 | 0.830816 | 8.836858 | 0.000000 | 50.523169 | 060730028011 | MULTIPOLYGON (((-117.10104 32.77904, -117.1009... |
| 3 | 542.0 | 840.0 | 891.0 | 1031.0 | 2316.0 | 988.0 | 844.0 | 060730038001018 | 060730038001 | 23.042338 | 1.255152 | 12.120644 | 0.309105 | 12.120644 | 0.000000 | 20.757082 | 060730038001 | MULTIPOLYGON (((-117.14516 32.68450, -117.1405... |
| 4 | 3459.0 | 2196.0 | 1479.0 | 3853.0 | 8092.0 | 2895.0 | 1468.0 | 060730053021009 | 060730053021 | 49.566528 | 0.263852 | 9.536374 | 0.000000 | 9.536374 | 34.201537 | 10.631939 | 060730053021 | MULTIPOLYGON (((-117.16649 32.71592, -117.1664... |
| 5 | 2347.0 | 812.0 | 646.0 | 1426.0 | 3788.0 | 1443.0 | 902.0 | 060730083121001 | 060730083121 | 8.728943 | 0.000000 | 10.413476 | 0.000000 | 10.413476 | 0.000000 | 100.000000 | 060730083121 | MULTIPOLYGON (((-117.26900 32.85116, -117.2661... |
| 6 | 1957.0 | 662.0 | 371.0 | 1095.0 | 3106.0 | 979.0 | 486.0 | 060730083391005 | 060730083391 | 10.738255 | 0.000000 | 26.006711 | 0.335570 | 26.006711 | 2.013423 | 69.031640 | 060730083391 | MULTIPOLYGON (((-117.26120 32.93794, -117.2612... |
| 7 | 2014.0 | 627.0 | 361.0 | 1048.0 | 2897.0 | 1153.0 | 525.0 | 060730083391018 | 060730083391 | 10.738255 | 0.000000 | 26.006711 | 0.335570 | 26.006711 | 2.013423 | 69.031640 | 060730083391 | MULTIPOLYGON (((-117.26120 32.93794, -117.2612... |
| 8 | 5547.0 | 1883.0 | 1231.0 | 3226.0 | 9104.0 | 2783.0 | 2154.0 | 060730083391034 | 060730083391 | 10.738255 | 0.000000 | 26.006711 | 0.335570 | 26.006711 | 2.013423 | 69.031640 | 060730083391 | MULTIPOLYGON (((-117.26120 32.93794, -117.2612... |
| 9 | 3247.0 | 1067.0 | 771.0 | 1768.0 | 5377.0 | 1476.0 | 1590.0 | 060730083462000 | 060730083462 | 8.688245 | 0.000000 | 19.931857 | 0.000000 | 19.931857 | 0.000000 | 88.045977 | 060730083462 | MULTIPOLYGON (((-117.22413 32.90562, -117.2239... |
| 10 | 2456.0 | 528.0 | 399.0 | 926.0 | 3537.0 | 772.0 | 718.0 | 060730083462024 | 060730083462 | 8.688245 | 0.000000 | 19.931857 | 0.000000 | 19.931857 | 0.000000 | 88.045977 | 060730083462 | MULTIPOLYGON (((-117.22413 32.90562, -117.2239... |
| 11 | 1758.0 | 1146.0 | 780.0 | 1690.0 | 4410.0 | 964.0 | 2343.0 | 060730083501024 | 060730083501 | 16.212534 | 0.000000 | 40.054496 | 0.000000 | 40.054496 | 9.054594 | 42.343542 | 060730083501 | MULTIPOLYGON (((-117.20624 32.89053, -117.2061... |
| 12 | 2230.0 | 1377.0 | 1059.0 | 1960.0 | 5030.0 | 1596.0 | 2170.0 | 060730083502006 | 060730083502 | 0.259516 | 1.816609 | 43.425606 | 1.816609 | 43.425606 | 3.645200 | 46.172539 | 060730083502 | MULTIPOLYGON (((-117.18963 32.89516, -117.1896... |
| 13 | 1886.0 | 1026.0 | 676.0 | 1670.0 | 4159.0 | 1099.0 | 1383.0 | 060730083692001 | 060730083692 | 3.254973 | 0.000000 | 20.524412 | 0.000000 | 20.524412 | 1.767956 | 80.552486 | 060730083692 | MULTIPOLYGON (((-117.24370 32.94995, -117.2435... |
| 14 | 527.0 | 530.0 | 446.0 | 714.0 | 1685.0 | 532.0 | 2676.0 | 060730083762000 | 060730083762 | 24.585635 | 0.000000 | 26.151013 | 0.828729 | 26.151013 | 0.000000 | 94.315545 | 060730083762 | MULTIPOLYGON (((-117.21407 32.86924, -117.2140... |
| 15 | 1798.0 | 579.0 | 343.0 | 907.0 | 3095.0 | 532.0 | 614.0 | 060730083763000 | 060730083763 | 4.781955 | 0.000000 | 38.736842 | 0.000000 | 38.736842 | 6.752554 | 70.546424 | 060730083763 | MULTIPOLYGON (((-117.20539 32.87431, -117.2050... |
| 16 | 7071.0 | 4113.0 | 2610.0 | 7266.0 | 15950.0 | 5110.0 | 2867.0 | 060730085111005 | 060730085111 | 19.012727 | 0.000000 | 30.775164 | 0.000000 | 30.775164 | 4.101382 | 73.410138 | 060730085111 | MULTIPOLYGON (((-117.14363 32.82766, -117.1410... |
| 17 | 1179.0 | 688.0 | 548.0 | 1100.0 | 2540.0 | 975.0 | 552.0 | 060730085111015 | 060730085111 | 19.012727 | 0.000000 | 30.775164 | 0.000000 | 30.775164 | 4.101382 | 73.410138 | 060730085111 | MULTIPOLYGON (((-117.14363 32.82766, -117.1410... |
| 18 | 1177.0 | 852.0 | 732.0 | 1128.0 | 2854.0 | 1035.0 | 947.0 | 060730085113001 | 060730085113 | 26.499303 | 0.000000 | 41.562064 | 0.000000 | 41.562064 | 4.323827 | 57.221711 | 060730085113 | MULTIPOLYGON (((-117.15231 32.81066, -117.1515... |
| 19 | 2558.0 | 1638.0 | 1179.0 | 2447.0 | 5386.0 | 2436.0 | 1350.0 | 060730085113004 | 060730085113 | 26.499303 | 0.000000 | 41.562064 | 0.000000 | 41.562064 | 4.323827 | 57.221711 | 060730085113 | MULTIPOLYGON (((-117.15231 32.81066, -117.1515... |
| 20 | 1633.0 | 890.0 | 644.0 | 1493.0 | 3389.0 | 1271.0 | 623.0 | 060730085113008 | 060730085113 | 26.499303 | 0.000000 | 41.562064 | 0.000000 | 41.562064 | 4.323827 | 57.221711 | 060730085113 | MULTIPOLYGON (((-117.15231 32.81066, -117.1515... |
| 21 | 2190.0 | 1128.0 | 714.0 | 1992.0 | 4288.0 | 1736.0 | 928.0 | 060730087021003 | 060730087021 | 26.323458 | 0.000000 | 13.453133 | 0.000000 | 13.453133 | 13.157895 | 33.815789 | 060730087021 | MULTIPOLYGON (((-117.15911 32.79187, -117.1589... |
| 22 | 1094.0 | 781.0 | 648.0 | 1198.0 | 2477.0 | 1244.0 | 1150.0 | 060730093074013 | 060730093074 | 14.777618 | 0.000000 | 6.312769 | 0.000000 | 6.312769 | 0.000000 | 69.924812 | 060730093074 | MULTIPOLYGON (((-117.15474 32.76425, -117.1546... |
| 23 | 1195.0 | 689.0 | 485.0 | 1254.0 | 2653.0 | 970.0 | 569.0 | 060730150022003 | 060730150022 | 29.085603 | 0.000000 | 4.863813 | 0.000000 | 4.863813 | 12.621359 | 20.249653 | 060730150022 | MULTIPOLYGON (((-117.01814 32.77758, -117.0178... |
| 24 | 1337.0 | 852.0 | 600.0 | 1370.0 | 3317.0 | 842.0 | 1091.0 | 060730170492019 | 060730170492 | 24.429802 | 0.000000 | 12.671059 | 2.128738 | 12.671059 | 15.659777 | 33.386328 | 060730170492 | MULTIPOLYGON (((-117.06007 32.93513, -117.0597... |
| 25 | 2555.0 | 989.0 | 612.0 | 1714.0 | 4066.0 | 1804.0 | 1002.0 | 060730170561002 | 060730170561 | 15.010142 | 0.000000 | 30.141988 | 0.000000 | 30.141988 | 6.474820 | 51.130524 | 060730170561 | MULTIPOLYGON (((-117.09551 32.96476, -117.0954... |
| 26 | 1867.0 | 668.0 | 465.0 | 1214.0 | 2866.0 | 1348.0 | 920.0 | 060730170711003 | 060730170711 | 11.128142 | 0.000000 | 38.749234 | 0.000000 | 38.749234 | 1.953819 | 62.477798 | 060730170711 | MULTIPOLYGON (((-117.11096 33.01728, -117.1108... |
| 27 | 1756.0 | 994.0 | 752.0 | 1380.0 | 3553.0 | 1329.0 | 1096.0 | 060730221012009 | 060730221012 | 0.000000 | 0.000000 | 18.850575 | 0.000000 | 18.850575 | 6.122449 | 17.857143 | 060730221012 | MULTIPOLYGON (((-117.32944 33.13456, -117.3293... |
In [96]:
lodes_acs.plot()
Out[96]:
<Axes: >
In [97]:
import pandana as pdna
import geopandas as gpd
import os
if not os.path.exists('41740.h5'):
import quilt3 as q3
b = q3.Bucket("s3://spatial-ucr")
b.fetch("osm/metro_networks_8k/41740.h5", "./41740.h5")
sd_network = pdna.Network.from_hdf5("41740.h5")
100%|██████████| 29.2M/29.2M [00:09<00:00, 3.18MB/s]
Generating contraction hierarchies with 32 threads. Setting CH node vector of size 332554 Setting CH edge vector of size 522484 Range graph removed 143094 edges of 1044968 . 10% . 20% . 30% . 40% . 50% . 60% . 70% . 80% . 90% . 100%
In [98]:
from random import sample
from geosnap.analyze import isochrones_from_gdf
In [99]:
iso = isochrones_from_gdf(lodes,threshold=4000, network=sd_network)
/opt/tljh/user/lib/python3.10/site-packages/geosnap/analyze/network.py:140: UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation. node_ids = network.get_node_ids(origins.centroid.x, origins.centroid.y).astype(int) /opt/tljh/user/lib/python3.10/site-packages/geosnap/analyze/network.py:34: UserWarning: Geometry is in a geographic CRS. Results from 'centroid' are likely incorrect. Use 'GeoSeries.to_crs()' to re-project geometries to a projected CRS before this operation. node_ids = network.get_node_ids(origins.centroid.x, origins.centroid.y).astype(int)
In [100]:
iso.explore()
Out[100]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [101]:
lodes_to_plot=['education_bachelors','education_hs','education_lths','education_some_college']
In [102]:
acs_to_plot=['p_edu_hs_less','p_edu_college_greater']
In [103]:
ages_to_plot=['employees_30_54','employees_55plus', 'employees_under_30']
In [104]:
import geopandas as gpd
In [105]:
gdf = gpd.GeoDataFrame(lodes_acs, geometry='geometry', crs="EPSG:4326")
In [106]:
fig, axs = plt.subplots(1, 2, figsize=(30, 20))
axs = axs.flatten()
for i, col in enumerate(acs_to_plot):
ax = axs[i]
gdf.plot(column=col, ax=ax, scheme="Quantiles", cmap='inferno', legend=True, legend_kwds={"fmt": "{:.2f}", 'bbox_to_anchor': (1.25, 0.5)})
ax.set_axis_off()
ax.set_title(col)
plt.show()
In [107]:
#people living closer to the coast have higher education levels than people living more inland
#concentration of employment centers is closer to coast
#lode = people working - lodes for people w college or greater is also higher closer to employment centers
In [108]:
lodes2=demographics.merge(lodes_demos, left_on='geoid', right_on='shortgeoid')
In [109]:
lodes_demos
Out[109]:
| education_bachelors | education_hs | education_lths | education_some_college | employees_30_54 | employees_55plus | employees_under_30 | geoid | shortgeoid | |
|---|---|---|---|---|---|---|---|---|---|
| 214 | 3266.0 | 1347.0 | 990.0 | 2136.0 | 6017.0 | 1722.0 | 2256.0 | 060730004002000 | 060730004002 |
| 229 | 1174.0 | 717.0 | 542.0 | 1187.0 | 2650.0 | 970.0 | 652.0 | 060730004004000 | 060730004004 |
| 1604 | 1620.0 | 563.0 | 321.0 | 871.0 | 2272.0 | 1103.0 | 632.0 | 060730028011010 | 060730028011 |
| 3062 | 542.0 | 840.0 | 891.0 | 1031.0 | 2316.0 | 988.0 | 844.0 | 060730038001018 | 060730038001 |
| 3859 | 3459.0 | 2196.0 | 1479.0 | 3853.0 | 8092.0 | 2895.0 | 1468.0 | 060730053021009 | 060730053021 |
| 4265 | 1152.0 | 975.0 | 638.0 | 1295.0 | 2719.0 | 1341.0 | 940.0 | 060730062001000 | 060730062001 |
| 5937 | 7181.0 | 2678.0 | 1747.0 | 4321.0 | 12173.0 | 3754.0 | 5185.0 | 060730083051007 | 060730083051 |
| 5948 | 2425.0 | 270.0 | 92.0 | 1152.0 | 2794.0 | 1145.0 | 324.0 | 060730083051018 | 060730083051 |
| 6079 | 2347.0 | 812.0 | 646.0 | 1426.0 | 3788.0 | 1443.0 | 902.0 | 060730083121001 | 060730083121 |
| 6410 | 1957.0 | 662.0 | 371.0 | 1095.0 | 3106.0 | 979.0 | 486.0 | 060730083391005 | 060730083391 |
| 6423 | 2014.0 | 627.0 | 361.0 | 1048.0 | 2897.0 | 1153.0 | 525.0 | 060730083391018 | 060730083391 |
| 6439 | 5547.0 | 1883.0 | 1231.0 | 3226.0 | 9104.0 | 2783.0 | 2154.0 | 060730083391034 | 060730083391 |
| 6519 | 3247.0 | 1067.0 | 771.0 | 1768.0 | 5377.0 | 1476.0 | 1590.0 | 060730083462000 | 060730083462 |
| 6543 | 2456.0 | 528.0 | 399.0 | 926.0 | 3537.0 | 772.0 | 718.0 | 060730083462024 | 060730083462 |
| 6676 | 1758.0 | 1146.0 | 780.0 | 1690.0 | 4410.0 | 964.0 | 2343.0 | 060730083501024 | 060730083501 |
| 6705 | 2230.0 | 1377.0 | 1059.0 | 1960.0 | 5030.0 | 1596.0 | 2170.0 | 060730083502006 | 060730083502 |
| 7096 | 1886.0 | 1026.0 | 676.0 | 1670.0 | 4159.0 | 1099.0 | 1383.0 | 060730083692001 | 060730083692 |
| 7218 | 527.0 | 530.0 | 446.0 | 714.0 | 1685.0 | 532.0 | 2676.0 | 060730083762000 | 060730083762 |
| 7222 | 1798.0 | 579.0 | 343.0 | 907.0 | 3095.0 | 532.0 | 614.0 | 060730083763000 | 060730083763 |
| 7690 | 7071.0 | 4113.0 | 2610.0 | 7266.0 | 15950.0 | 5110.0 | 2867.0 | 060730085111005 | 060730085111 |
| 7700 | 1179.0 | 688.0 | 548.0 | 1100.0 | 2540.0 | 975.0 | 552.0 | 060730085111015 | 060730085111 |
| 7768 | 1177.0 | 852.0 | 732.0 | 1128.0 | 2854.0 | 1035.0 | 947.0 | 060730085113001 | 060730085113 |
| 7771 | 2558.0 | 1638.0 | 1179.0 | 2447.0 | 5386.0 | 2436.0 | 1350.0 | 060730085113004 | 060730085113 |
| 7775 | 1633.0 | 890.0 | 644.0 | 1493.0 | 3389.0 | 1271.0 | 623.0 | 060730085113008 | 060730085113 |
| 7886 | 2190.0 | 1128.0 | 714.0 | 1992.0 | 4288.0 | 1736.0 | 928.0 | 060730087021003 | 060730087021 |
| 8522 | 1094.0 | 781.0 | 648.0 | 1198.0 | 2477.0 | 1244.0 | 1150.0 | 060730093074013 | 060730093074 |
| 14242 | 1195.0 | 689.0 | 485.0 | 1254.0 | 2653.0 | 970.0 | 569.0 | 060730150022003 | 060730150022 |
| 16871 | 1337.0 | 852.0 | 600.0 | 1370.0 | 3317.0 | 842.0 | 1091.0 | 060730170492019 | 060730170492 |
| 17007 | 2555.0 | 989.0 | 612.0 | 1714.0 | 4066.0 | 1804.0 | 1002.0 | 060730170561002 | 060730170561 |
| 17563 | 1867.0 | 668.0 | 465.0 | 1214.0 | 2866.0 | 1348.0 | 920.0 | 060730170711003 | 060730170711 |
| 28563 | 1756.0 | 994.0 | 752.0 | 1380.0 | 3553.0 | 1329.0 | 1096.0 | 060730221012009 | 060730221012 |
In [110]:
lodes_demos.plot()
Out[110]:
<Axes: >
In [111]:
demographics.plot()
Out[111]:
<Axes: >
In [112]:
lodes2.plot()
Out[112]:
<Axes: >
In [113]:
combined = gpd.sjoin(lodes2,demographics, op='within')
/opt/tljh/user/lib/python3.10/site-packages/IPython/core/interactiveshell.py:3493: FutureWarning: The `op` parameter is deprecated and will be removed in a future release. Please use the `predicate` parameter instead. if await self.run_code(code, result, async_=asy):
In [114]:
combined.explore()
Out[114]:
Make this Notebook Trusted to load map: File -> Trust Notebook
The explore map above shows the demographic and age data for the employment ceters (combines lodes (employees,'right') and acs(residents, 'left')), hover on each isochrone to see the exact numbers for each category¶
In [115]:
gdf.explore()
# same data but in a geodataframe
Out[115]:
Make this Notebook Trusted to load map: File -> Trust Notebook
In [116]:
lodes_to_plot
Out[116]:
['education_bachelors', 'education_hs', 'education_lths', 'education_some_college']
In [117]:
fig, axs = plt.subplots(2, 2, figsize=(30, 20))
axs = axs.flatten()
for i, col in enumerate(lodes_to_plot):
ax = axs[i]
gdf.plot(column=col, ax=ax, scheme="Quantiles", cmap='BuPu', legend=True, legend_kwds={"fmt": "{:.2f}", 'bbox_to_anchor': (1.25, 0.5)})
ax.set_axis_off()
ax.set_title(col)
plt.show()
In [118]:
fig, axs = plt.subplots(1, 3, figsize=(30, 20))
axs = axs.flatten()
for i, col in enumerate(ages_to_plot):
ax = axs[i]
gdf.plot(column=col, ax=ax, scheme="Quantiles", cmap='BuPu', legend=True, legend_kwds={"fmt": "{:.2f}", 'bbox_to_anchor': (1.25, 0.5)})
ax.set_axis_off()
ax.set_title(col)
plt.show()
In [119]:
iso.plot()
Out[119]:
<Axes: >
In [120]:
import geopandas as gpd
import matplotlib.pyplot as plt
fig, axs = plt.subplots(3, 1, figsize=(30, 20))
axs = axs.flatten()
for i, col in enumerate(ages_to_plot):
ax = axs[i]
gdf.plot(column=col, ax=ax, scheme="Quantiles", cmap='spring', legend=True, legend_kwds={"fmt": "{:.2f}", 'bbox_to_anchor': (1.25, 0.5)})
ax.set_title(col)
sd_tracts.plot(ax=ax, color='none', edgecolor='gray',linewidth=0.5)
plt.show()
the various maps shown above refelct the demographics in lodes(employees) and census (residents) and this helps to compare who is close to employment centers¶
In [121]:
fig, axs = plt.subplots(2, 2, figsize=(30, 20))
axs = axs.flatten()
for i, col in enumerate(lodes_to_plot):
ax = axs[i]
gdf.plot(column=col, ax=ax, scheme="Quantiles", cmap='spring', legend=True, legend_kwds={"fmt": "{:.2f}", 'bbox_to_anchor': (1.25, 0.5)})
ax.set_axis_off()
ax.set_title(col)
sd_tracts.plot(ax=ax, color='none', edgecolor='gray',linewidth=0.5)
plt.show()
## education of employees in the specified geographic areas
In [122]:
fig, axs = plt.subplots(2, 2, figsize=(30, 20))
axs = axs.flatten()
for i, col in enumerate(lodes_to_plot):
ax = axs[i]
gdf.plot(column=col, ax=ax, scheme="Quantiles", cmap='spring', legend=True, legend_kwds={"fmt": "{:.2f}", 'bbox_to_anchor': (1.25, 0.5)})
ax.set_axis_off()
ax.set_title(col)
sd_tracts.plot(ax=ax, color='none', edgecolor='gray',linewidth=0.5)
iso.plot(ax=ax,color='none', edgecolor='mediumseagreen')
plt.show()
## education of employees in specified geographic areas combined withh employment centers
In [123]:
## employment centers in general seem to have higher education levels for the employees and more specifically, employment centers along the coast while closer to inland employment centers have lower education for employees and also for residents (see below maps)
In [124]:
fig, axs = plt.subplots(1, 2, figsize=(30, 20))
axs = axs.flatten()
for i, col in enumerate(acs_to_plot):
ax = axs[i]
gdf.plot(column=col, ax=ax, scheme="Quantiles", cmap='spring', legend=True, legend_kwds={"fmt": "{:.2f}", 'bbox_to_anchor': (1.25, 0.5)})
ax.set_axis_off()
ax.set_title(col)
sd_tracts.plot(ax=ax, color='none', edgecolor='gray')
plt.show()
##education levels of residents of geographic areas